//
//  TopicCell.m
//  HappyTrip
//
//  Created by dlios on 15-3-24.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "TopicCell.h"

@implementation TopicCell

- (void)dealloc
{
    [_titleImage release];
    [_labelImage1 release];
    [_labelImage2 release];
    [_textLabel1 release];
    [_textLabel2 release];
    [_titleLabel release];
    [_topicLabel1 release];
    [_topicLabel2 release];
    [_recommend release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.titleLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.titleLabel];
        self.titleImage = [[UIImageView alloc] init];
        [self.titleLabel addSubview:self.titleImage];
        [_titleImage release];
        [_titleLabel release];
        
        self.topicLabel1 = [[UILabel alloc] init];
        [self.contentView addSubview:self.topicLabel1];
        self.labelImage1 = [[UIImageView alloc] init];
        [self.topicLabel1 addSubview:self.labelImage1];
        [_labelImage1 release];
        [_topicLabel1 release];
        
        self.topicLabel2 = [[UILabel alloc] init];
        [self.contentView addSubview:self.topicLabel2];
        self.labelImage2 = [[UIImageView alloc] init];
        [self.topicLabel2 addSubview:self.labelImage2];
        [_labelImage2 release];
        [_topicLabel2 release];
        
        self.textLabel1 = [[UILabel alloc] init];
        self.textLabel1.backgroundColor = [UIColor groupTableViewBackgroundColor];
        [self.contentView addSubview:self.textLabel1];
        [_textLabel1 release];
        
        self.textLabel2 = [[UILabel alloc] init];
        self.textLabel2.backgroundColor = [UIColor groupTableViewBackgroundColor];
        [self.contentView addSubview:self.textLabel2];
        [_textLabel2 release];
    }
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    CGFloat width = self.contentView.bounds.size.width;
    CGFloat heigth = (self.contentView.bounds.size.height - 30) / 2;
    
    self.titleLabel.frame = CGRectMake(10, 0, width - 20, 30);
    if (self.recommend.title != nil) {
        
        self.titleLabel.text = [NSString stringWithFormat:@" %@", self.recommend.title];
        self.titleImage.frame = CGRectMake(0, 5, 3, 20);
        self.titleImage.image = [UIImage imageNamed:@"ticket_@2x.png"];

        self.topicLabel1.frame = CGRectMake(10, 35, width - 20, heigth - 7.5);
        self.labelImage1.frame = CGRectMake(0, 0, self.topicLabel1.bounds.size.width, self.topicLabel1.bounds.size.height * 2 / 3);
        NSString *str = [[self.recommend.data objectAtIndex:0] objectForKey:@"cover"];
        NSURL *url = [NSURL URLWithString:str];
        [self.labelImage1 setImageWithURL:url placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
        self.topicLabel1.text = [NSString stringWithFormat:@"%@", [[self.recommend.data objectAtIndex:0] objectForKey:@"url"]];
        
        
        self.topicLabel2.frame = CGRectMake(10, heigth + 37.5, width - 20, heigth - 5);
        self.labelImage2.frame = CGRectMake(0, 0, self.topicLabel1.bounds.size.width, self.topicLabel1.bounds.size.height * 2 / 3);
        NSString *str2 = [[self.recommend.data objectAtIndex:1] objectForKey:@"cover"];
        NSURL *url2 = [NSURL URLWithString:str2];
        [self.labelImage2 setImageWithURL:url2 placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
        self.topicLabel2.text = [NSString stringWithFormat:@"%@", [[self.recommend.data objectAtIndex:1] objectForKey:@"url"]];
        
        self.textLabel1.frame = CGRectMake(12.5, heigth * 2 / 3 + 32.5, width - 25, heigth / 3 - 7.5);
        self.textLabel1.text = [NSString stringWithFormat:@"%@", [[self.recommend.data objectAtIndex:0] objectForKey:@"text"]];
        self.textLabel1.numberOfLines = 0;
        
        self.textLabel2.frame = CGRectMake(12.5, heigth * 5 / 3 + 35, width - 25, heigth / 3 - 7.5);
        self.textLabel2.text = [NSString stringWithFormat:@"%@", [[self.recommend.data objectAtIndex:1] objectForKey:@"text"]];
        self.textLabel2.numberOfLines = 0;
    }

}

//- (UIImageView *)getView:(NSInteger)index
//{
//    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.topicLabel1.bounds.size.width, self.topicLabel1.bounds.size.height * 2 / 3)];
//    NSString *str = [[self.recommend.data objectAtIndex:index] objectForKey:@"cover"];
//    NSURL *url = [NSURL URLWithString:str];
//    [imageView setImageWithURL:url placeholderImage:[UIImage imageNamed:@"placeholder.jpg"]];
//    return [imageView autorelease];
//}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
